package com.utils;


import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SpringUtil {



	public static ApplicationContext ctx;

	public static void getApplicationContext() {

		String[] configFiles = new String[] { "/applicationContext.xml", "applicationContext-*.xml" };
		ctx = new ClassPathXmlApplicationContext(configFiles);
	}

	@SuppressWarnings("unchecked")
	public static <T> T getBean(String name) {
		if (ctx == null) {
			getApplicationContext();
		}
		T bean = (T) ctx.getBean(name);
		return bean;
	}
}
